package com.ftf.tp.user.infrastructure.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 数据库自动填充字段
 *
 * @author tanghao
 * @date 2021/08/12
 */
@Component
public class TpMetaObjectHandler implements MetaObjectHandler {

    /**
     * 插入操作时自动填充
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createdTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updatedTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "lookAmount", Integer.class, 0);
        this.strictInsertFill(metaObject, "supportAmount", Integer.class, 0);
        this.strictInsertFill(metaObject, "collectionAmount", Integer.class, 0);
        this.strictInsertFill(metaObject, "commentAmount", Integer.class, 0);
        this.strictInsertFill(metaObject, "hotValue", Integer.class, 0);
        this.strictInsertFill(metaObject, "deleteStatus", Integer.class, 0);
        this.strictInsertFill(metaObject, "tagStatus", Boolean.class, true);
        this.strictInsertFill(metaObject, "followNumber", Integer.class, 0);
    }


    /**
     * 更新操作时自动填充
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updatedTime", Date.class, new Date());
    }
}